import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)   //在这个项目中安装这个依赖，默认会调用install这个方法

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path:'/news',
    name: 'News',
    //路由的懒加载
    component: () => import(/* webpackChunkName: "about" */ '@/views/News.vue'),
    children:[
      {
        path:'NewsDetail/:id',
        component:()=>import('@/views/NewsDetail.vue'),
        props:true,
      }
    ]
  },
  // {
  //   // path: '/news/:a',  //单个值
  //   path:'/news/:a/:b',  //多个值
  //   name: 'News',
  //   //路由的懒加载
  //   component: () => import(/* webpackChunkName: "about" */ '@/views/News.vue') 
  // },
  {
    //*:可以匹配所有路径
    path:'*',
    name:'NotFound',
    component: ()=>import('@/views/NotFound.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
